
package com.shangsi.controller;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * 降级配置
 * @author dzd
 * @date 2021-12-18
 */
@RestController
public class SentinelHotKeyController {

    /**
     * 降级的配置
     * @return str
     */
    @RequestMapping("testHotKey")
    @SentinelResource(value = "testHotKey",fallback = "handleHotKey")
    public String testHotKey(@RequestParam(value = "p1",required = false)String p1,@RequestParam(value = "p2",required = false)String p2) throws InterruptedException {
        //TimeUnit.SECONDS.sleep(1);
        System.out.println("testHotKey "+System.currentTimeMillis());
        return "测试是否降级 P1:"+p1+" p2:"+p2;
    }

    /**
     * 限流兜底方法
     * @param p1 p1
     * @param p2 p2
     * @return Str
     */
    public String handleHotKey(String p1,String p2){

        return "handleHotKey (T||T)555555555555 ";
    }
}
